package com.envper.controller.device;

import com.envper.common.domain.dto.DeviceThresholdDto;
import com.envper.common.service.device.DeviceThresholdService;
import com.envper.mysql.domain.Result;
import com.envper.mysql.domain.Status;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/device/threshold")
public class ThresholdController {
    private final DeviceThresholdService deviceThresholdService;

    @GetMapping("/list")
    public Result<List<DeviceThresholdDto>> getDeviceThresholdList() {
        List<DeviceThresholdDto> deviceThresholdList = deviceThresholdService.getDeviceThresholdList();
        return Result.ok(Status.SUCCESS, deviceThresholdList);
    }

    @PostMapping("/create")
    public Result<String> createDeviceThreshold(@RequestBody DeviceThresholdDto deviceThresholdDto) {
        deviceThresholdService.createDeviceThreshold(deviceThresholdDto);
        return Result.ok(Status.CREATESUCCESS);
    }

    @DeleteMapping("/delete")
    public Result<String> deleteDeviceThreshold(@RequestParam("id") Long id) {
        deviceThresholdService.deleteDeviceThreshold(id);
        return Result.ok(Status.REMOVESUCCESS);
    }

    @PutMapping("/edit")
    public Result<String> editDeviceThreshold(@RequestBody DeviceThresholdDto deviceThresholdDto) {
        deviceThresholdService.editDeviceThreshold(deviceThresholdDto);
        return Result.ok(Status.UPDATESUCCESS);
    }


}
